package com.xinwei.leetcode.数组;
// https://leetcode-cn.com/problems/sort-colors/
// 按0、1、2排序
public class _75_颜色分类 {
    public void sortColors(int[] nums) {
        int red = 0;
        int white = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1) {
                System.out.println(red + "   " + white);
                nums[i] = nums[white];
                nums[white] = 1;
                white++;
            }else if (nums[i] == 0) {
                nums[i] = nums[red];
                nums[red] = 0;
                if (red < white) {
                    nums[i] = nums[white];
                    nums[white] = 1;
                }
                red++;
                white++;
            }
        }
    }
}
